var app = new Vue({
    el: '.promotiondetail',
    data() {
        return {
            myinvitation:{ //推广用户列表
                p:1, //当前页数
                s:12, //每页条数
                total:null,//总条数
                list:[], //当前页数返回数组
                showpage:5 //默认显示页数5个页
            },
            usercommision:{ //推广详情
                coin:'', //当前币种
                p:1, //当前页数
                s:10, //每页条数
                total:null,//总条数
                list:[], //当前页数返回数组
                showpage:5, //默认显示页数5个页
                brokerage:null
            },
            showitem:null
        }
    },
    created(){
        var test = window.location.href
        let coin = test.substring(test.indexOf("coin") + 5)
        let id = test.substring(test.indexOf("id") + 3, test.indexOf("&"))
        this.location = location.href.split('/')[0]+'//'+location.href.split('/')[2]+'/'///l;k;llk
        this.showitem = id
        this.usercommision.coin=coin
        if(id == 1){
            let params={
                coin:this.usercommision.coin,
                p:this.usercommision.p,
                s:this.usercommision.s
            }
            this.getCommision(params)
        }else if(id == 0){
            let params2={
                p:this.myinvitation.p,
                s:this.myinvitation.s
            }
            this.getInvitations(params2)
        }
    },
    mounted(){
        let _this = this
        if(this.showitem == 1){
            window.addEventListener('scroll',function(){  
                let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
                if(scrollTop + window.innerHeight >= document.body.offsetHeight) { 
                    setTimeout(() => {
                    //     _this.usercommision.s += 5
                    //     let params={
                    //         coin:_this.usercommision.coin,
                    //         p:_this.usercommision.p,
                    //         s:_this.usercommision.s
                    //     }
                    //     _this.getCommision(params)
                    },1000)  

                } 
            })
        }else if(this.showitem == 0){
            window.addEventListener('scroll',function(){  
                let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
                if(scrollTop + window.innerHeight >= document.body.offsetHeight) { 
                    setTimeout(() => {
                        // _this.myinvitation.s += 5
                        // let params2={
                        //     p:_this.myinvitation.p,
                        //     s:_this.myinvitation.s
                        // }
                        // _this.getInvitations(params2)
                    },1000)   
                } 
            })
        }
    },
    methods:{
        unesca(){
            let _this = this
            _this.usercommision.s += 9
            let params={
                coin:_this.usercommision.coin,
                p:_this.usercommision.p,
                s:_this.usercommision.s
            }
            _this.getCommision(params)
        },
        unescaa(){
            let _this = this
            _this.myinvitation.s += 9
            let params2={
                p:_this.myinvitation.p,
                s:_this.myinvitation.s
            }
            _this.getInvitations(params2)
        },
        getCookie(cookiename) { //获取cookie
            var arr,
              reg = new RegExp("(^| )" + cookiename + "=([^;]*)(;|$)");
            if ((arr = document.cookie.match(reg))) {
              return unescape(arr[2]);
            } else {
              return null;
            }
        },
        getInvitations(obj=null){ //获取推广用户
            axios.post('/user/myinvitation',obj).then((res) => {
                if(res.data.code==200){
                    // this.myinvitation.list=res.data.data.list
                    // this.myinvitation.total=res.data.data.total||0
                    this.myinvitation.list=res.data.data.first
                    this.myinvitation.total=res.data.data.first.length||0
                }
            })
        },
        getcurrentInvitations(num){ //分页获取推广用户
            this.myinvitation.p=num
            let params={
                p:this.myinvitation.p,
                s:this.myinvitation.s
            }
            this.getInvitations(params)
        },
        getCommision(obj=null){ //获取推广详情
            axios.post('/user/mobile/getCommision',obj).then((res) => {
                // if(res.data.code==200){
                   this.usercommision.list=res.data.data.list
                   this.usercommision.total=res.data.data.total
                   this.usercommision.brokerage=res.data.data.data2
                // }
            })
        },
        getcurrentCommision(num){ //分页获取推广详情
            this.usercommision.p=num
            let params2={
                p:this.usercommision.p,
                s:this.usercommision.s
            }
            this.getCommision(params2)
        },
        getTime: function (time) { //计算时间
            if(!time){
                return ''
            }
            var timeStr = time;
            var t = new Date(timeStr) 
            function charLeftAll(n) {
                if (n < 10) return "0" + n;
                else return n;
            }
            return t.getFullYear() + '-' + charLeftAll((t.getMonth() + 1)) + '-' + charLeftAll(t.getDate()) + '  ' +
                charLeftAll(t.getHours()) + ':' + charLeftAll(t.getMinutes()) + ':' + charLeftAll(t.getSeconds())
        },
        InterceptionMailbox: function (time) { //截取邮箱
            var str=time;
            var arr=str.split(" ");
            return arr[3]
        },
    }
})